package com.seb.cc.gtou.utils;

import java.util.ArrayList;
import java.util.List;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;

import com.cyrilmottier.polaris.Annotation;
import com.cyrilmottier.polaris.MapCalloutView;
import com.cyrilmottier.polaris.PolarisMapView;
import com.cyrilmottier.polaris.internal.AnnotationsOverlay;
import com.cyrilmottier.polaris.internal.OverlayContainer;
import com.cyrilmottier.polaris.internal.AnnotationsOverlay.MystiqueCallback;
import com.cyrilmottier.polaris.internal.OverlayContainer.MagnetoCallback;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import com.seb.cc.ttou.R;

public class CustomOverlay extends AnnotationsOverlay {

	private static Drawable marker;
	private static final String TAG = "CustomOverlay";
	private ArrayList<Annotation> mark = new ArrayList<Annotation>();
	private static PolarisMapView view;
	private MystiqueCallback mMystic;

	public CustomOverlay(List<Annotation> annotations, Drawable defaultMarker,
			PolarisMapView mapView, MystiqueCallback callback) {
		super(callback, annotations, defaultMarker);
		mMystic = callback;
		marker = defaultMarker;
		view = mapView;
	}

	@Override
	public boolean onTap(GeoPoint p, MapView mapView) {
		if (!super.onTap(p, mapView)) {
			Log.v(TAG,
					"I clicked on point" + p.getLatitudeE6() + ": "
							+ p.getLongitudeE6());

			GeoPoint selectedPoint = new GeoPoint(p.getLatitudeE6(),
					p.getLongitudeE6());
			// TODO set text as ressource
			List<Annotation> annot = new ArrayList<Annotation>();
			Annotation current = new Annotation(selectedPoint, "Cool", view
					.getResources().getString(R.string.gtouMapText), marker);
			annot.add(current);

			mark.removeAll(mark);
			mark.add(current);

			view.removeOverlay(this);
			CustomOverlay over = new CustomOverlay(mark, marker, view, mMystic);
			view.addOverlay(over);

			view.setAnnotations(annot, marker);
			view.setSelectedAnnotation(0);
		}
		return true;

	}

}
